﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using Entities;

namespace InsuranceVehicle.AdminSite
{
    public partial class ReportPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            EmployeeInfo emp = new EmployeeInfo();
            emp = (EmployeeInfo)Session["Employee"];
            if (emp != null)
            {
                if (emp.Department == 1)
                {
                    Menu1.ShowElement = "all";
                }
                else
                {
                    Menu1.ShowElement = "no";
                }
                showAllPolicy();

            }
            else
            {
                Response.Redirect("LoginAdmin.aspx");
            }

        }

        public void showAllPolicy()
        {
            InsurancePolicyAccess ipa = new InsurancePolicyAccess();
            List<InsurancePolicyInfo> listInsu = new List<InsurancePolicyInfo>();
            listInsu = ipa.getAllPolicy();

            Repeater1.DataSource = listInsu;
            Repeater1.DataBind();
        }

        protected void btnShow_Click(object sender, EventArgs e)
        {
            if (chooseEndDate.IsEmpty || chooseStartDate.IsEmpty)
            {
                showAllPolicy();

            }
            else
            {
                DateTime startDate = Convert.ToDateTime(chooseStartDate.SelectedDate.Value.ToShortDateString());
                DateTime endDate = Convert.ToDateTime(chooseEndDate.SelectedDate.Value.ToShortDateString());

                InsurancePolicyAccess ipa = new InsurancePolicyAccess();
                List<InsurancePolicyInfo> listInsu = new List<InsurancePolicyInfo>();

                listInsu = ipa.getListOfPolicyByDate(startDate, endDate);
                Repeater1.DataSource = listInsu;
                Repeater1.DataBind();
            }
            
        }

        protected void btnShowAll_Click(object sender, EventArgs e)
        {
            showAllPolicy();
        }


    }
}